#include <iostream>
#include <memory>

using std::cout;
using std::endl;
using std::auto_ptr;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy )
    {
        cout << "Point(int = 0, int = 0)" << endl;
    }

    void print() const
    {
        cout << "(" << _ix 
             << ", " << _iy
             << ")" << endl;
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};
void test()
{
    //auto_ptr是智能指针
    auto_ptr<Point> ap(new Point(1, 2));
    ap->print();
}

void test2()
{
    //pInt裸指针
    int *pInt = new int(10);
    auto_ptr<int> ap(pInt);
    cout << "*pInt = " << *pInt << endl;
    cout << "*ap = " << *ap << endl;

    cout << endl;
    //在代码层面可以进行复制操作，但是底层已经发生了所有权的
    //转移,所以该复制操作存在缺陷
    auto_ptr<int>  ap2(ap);
    cout << "*ap2 = " << *ap2 << endl;
    cout << "*ap = " << *ap << endl;
}

int main(int argc, char *argv[])
{
    test2();
    return 0;
}

